package com.itfreer.file;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

/**
 * 定义对象处理基类，解决bean工厂等问题
 */
public abstract class ObjectBase implements BeanFactoryAware {

	protected static BeanFactory beanFactory;

	@Override
	public void setBeanFactory(BeanFactory bf) throws BeansException {
		beanFactory = bf;
	}
	
	private FilePathPara pathPara;
	
	protected FilePathPara getPara(){
		if(pathPara==null){
			pathPara = (FilePathPara) beanFactory.getBean("filePathPara");
		}
		return pathPara;
	}
	
	protected String getBasePath(){
		String basepath = getPara().getFilePath();
		if(basepath==null || basepath.trim().equals("")){
			basepath = this.getClass().getClass().getResource("/").getPath();
			basepath += "upload/";
		}
		return basepath;
	}
	
}